<template>
  <section class="login">
    <el-form :model="form" :rules="rules" ref="form">
      <el-form-item prop="username">
        <input type="text" placeholder="用户名" v-model="form.username" />
      </el-form-item>
      <el-form-item prop="password">
        <input type="text" placeholder="密码" v-model="form.password" />
      </el-form-item>
      <button class="button" @click.stop.prevent="loginButton">登录</button>
      <div class="avatar">
        <img src="@/assets/微信图片_20220126160640.jpg" />
      </div>
    </el-form>
  </section>
</template>

<script>
export default {
  data () {
    return {
      form: {
        username: 'admin',
        password: '123456'
      },
      rules: {
        username: [
          { required: true, message: '用户名不能为空', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '密码不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    async loginButton () {
      try {
        await this.$refs.form.validate()
        await this.$store.dispatch('login', this.form)
        this.$router.push('/')
      } catch (err) {
        console.log(err)
      }
    }
  }
}
</script>

<style lang="less" scoped>
.login {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(
    to right top,
    #333744 0%,
    rgba(26, 29, 56, 0.637) 100%
  );
  overflow: hidden;
  padding: 0 10px 10px;
  box-sizing: border-box;
  &::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    z-index: 2;
    width: 300px;
    height: 300px;
    transform: translate(10%, 20%);
    border-radius: 50%;
    background: linear-gradient(
      to right top,
      hsla(259, 84%, 78%, 1) 0%,
      hsla(206, 67%, 75%, 1) 60%,
      #33d9b2 100%
    );
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.2);
    animation: pulse 1.6s infinite;
  }
  &::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    z-index: 2;
    width: 450px;
    height: 450px;
    transform: translate(-100%, -80%);
    border-radius: 50%;
    background: linear-gradient(
      to right bottom,
      hsla(42, 93%, 57%, 1) 0%,
      hsla(358, 78%, 62%, 1) 100%
    );
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.2);
    animation: pulse 1.6s infinite;
  }
  & > .el-form {
    position: relative;
    z-index: 3;
    width: 360px;
    background-color: rgba(255, 255, 255, 0.1);
    padding: 30px;
    padding-top: 100px;
    border-radius: 8px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px);
  }
  input {
    width: 100%;
    height: 50px;
    background-color: transparent;
    border: 1px solid rgba(255, 255, 255, 0.5);
    outline: none;
    border-radius: 8px;
    margin-bottom: 5px;
    padding-left: 15px;
    color: #fff;
    box-sizing: border-box;
    &::placeholder {
      color: #fff;
    }
  }
  .button {
    width: 100%;
    height: 50px;
    border: 0;
    background: linear-gradient(to right bottom, #7a8fd3, #45cde9);
    background-size: 200% auto;
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    transition: ease 0.4s;
    font-size: 20px;
    &:hover {
      background-position: right center;
      text-decoration: none;
    }
  }
  ::v-deep .el-form-item__error {
    color: #fff !important;
    padding-left: 15px;
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.329);
  }
}

@keyframes pulse {
  50% {
    box-shadow: 0 0 0 50px rgba(255, 255, 255, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0);
  }
}
.avatar {
  position: absolute;
  left: 50%;
  top: 0;
  width: 130px;
  height: 130px;
  transform: translate(-50%, -50%);
  background-color: #f5f7f8a1;
  border: 1px solid #eee;
  box-shadow: 0 0 3px 3px rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  overflow: hidden;
  img {
    width: 80%;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    background-color: #eee;
    border-radius: 50%;
    border: 1px solid #eee;
  }
}
</style>
